package ca.jerg.wizard;

import java.util.StringTokenizer;
import com.nexes.wizard.WizardPanelDescriptor;

public class ErgWizardSetDescriptor extends WizardPanelDescriptor
{
	public static final String IDENTIFIER = "SET_PANEL_0";
	public static final String ID_PREFACE = "SET_PANEL_";

	private ErgWizard ergWizard;
	private ErgWizardSetPanel set;
	private Object nextPanel;
	private Object backPanel;
	
	public ErgWizardSetDescriptor( ErgWizard erg )
	{
		super(IDENTIFIER,new ErgWizardSetPanel());
		setDefaultPanels();		
		ergWizard = erg;
		
        // reference to the controls on the start panel
        set = (ErgWizardSetPanel)super.getPanelComponent();		
	}
	
	public ErgWizardSetDescriptor( int id, ErgWizard erg )
	{
		super(ID_PREFACE + id,new ErgWizardSetPanel(id + 1));
		setDefaultPanels();
		ergWizard = erg;
		
        // reference to the controls on the start panel
        set = (ErgWizardSetPanel)super.getPanelComponent();		
	}

	public Object getNextPanelDescriptor() 
	{		
		return nextPanel;
	}

	public void setNextPanelDescriptor( Object o )
	{
		nextPanel = o;
	}

	public Object getBackPanelDescriptor() 
	{
		return backPanel;
	}

	public void setBackPanelDescriptor( Object o )
	{
		backPanel = o;
	}
	
	public void setDefaultPanels()
	{
		nextPanel = ErgWizardWarmUpDescriptor.IDENTIFIER;
		backPanel = ErgWizardStartDescriptor.IDENTIFIER;
	}
	
	public void aboutToHidePanel()
	{
		// determine our set number
		String token = null;
		StringTokenizer id = new StringTokenizer((String)this.getPanelDescriptorIdentifier(),"_");
		
		while ( id.hasMoreTokens() )
			token = id.nextToken();
		
		int index = Integer.parseInt(token);
		
		// grab the set details
		int numRepeats = Integer.parseInt(set.getNumRepeats());
		
		ErgWizardSetData setData = new ErgWizardSetData(set.getType(),numRepeats);
		
		ergWizard.addSet(index,setData);		
	}
}
